home *** CD-ROM | disk | FTP | other *** search
- Path: keats.ugrad.cs.ubc.ca!not-for-mail
- From: c2a192@ugrad.cs.ubc.ca (Kazimir Kylheku)
- Newsgroups: comp.lang.c,comp.unix.programmer
- Subject: Re: Wildcard Expansion in Unix
- Followup-To: comp.unix.programmer
- Date: 6 Mar 1996 13:11:50 -0800
- Organization: Computer Science, University of B.C., Vancouver, B.C., Canada
- Message-ID: <4hkv2mINN4qm@keats.ugrad.cs.ubc.ca>
- References: <313DE8F4.1478@ee.gatech.edu>
- NNTP-Posting-Host: keats.ugrad.cs.ubc.ca
-
- In article <313DE8F4.1478@ee.gatech.edu>,
- Chris Lanciani <lanciani@ee.gatech.edu> wrote:
- >Does anyone know of a way to perform wildcard expansion, in C,
- >on unix platforms? That is, if I write a program that accepts
- >filenames as input arguments, how can I make it handle
- >"?" and "*" correctly?
-
- Normally you don't. Your shell expands these regular expressions into an
- extended argument list that is passed to the program. The advantage of this is
- that it simplifies your program, and allows you to use a variety of shells
- that support various kinds of pattern matching. The disadvantage is that most
- UNIX systems have a kernel-imposed limit on the amount of argument and
- evironment space that can be passed to a process, and that with this method an
- interactive program can't use new globbing patterns once it has started (e.g.
- ones derived as user input, or from configuration or script files).
-
- >I am aware of the findfirst() and findnext() functions for the
- >PC (with Borland's compiler, at least), but the portability
-
- Those functions are part of MS-DOS. They are nasty in that there is a global
- context for findfirst()/findnext(). They are not not re-entrant, and therefore
- tricky to use recursively.
-
- >table for these functions does not include unix systems. I
-
- UNIX systems have a POSIX.1 standardized mechanism for reading directories
- known as the ``dirent'' functions. These are re-entrant. You open a dirent
- stream associated with a directory, and than read the elements of the directory
- as a stream, independently of other open streams. These functions are discussed
- in K&R2. However, they don't do pattern matching.
-
- >also know that Borland includes a .obj file that can be linked
- >with the program that does the wildcard expansion for you.
- >Does such a thing exist with gcc on unix?
-
- The shell does that in UNIX.
-
- There is also a function known as glob() that you can use for filename pattern
- expansion when you need to do it inside your program. This is standardized by
- POSIX.2. Your system may have a manual page on ``glob''. The glob() function
- will actually search the filesystem for files that match your expression.
-
- [ redirected to comp.unix.programmer ]
-
-
-
-
- >Thanks for any hints.
- >--
- >
- >Chris
- > Lanciani
- >lanciani@eedsp.gatech.edu
-
-
- --
-
-